package cn.easybuy.service.impl;

import java.sql.Connection;
import java.util.List;

import cn.easybuy.dao.ProductDao;
import cn.easybuy.dao.impl.ProductDaoImpl;
import cn.easybuy.entity.Category;
import cn.easybuy.entity.Page;
import cn.easybuy.entity.Product;
import cn.easybuy.service.ProductService;
import cn.easybuy.utils.DataSourceUtil;

public class ProductServiceImpl implements ProductService {
	private Connection conn;
	
	/**
	 * @throws Exception */
	@Override
	public List<Product> findProductList(Page page) throws Exception {
		try {
			conn = DataSourceUtil.getConnection();
			ProductDao pd = new ProductDaoImpl(conn);
			return pd.findProductList(page);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			DataSourceUtil.closeAll(conn, null, null);
		}
	}

	@Override
	public int ProductTotalCount() throws Exception {
		try {
			conn = DataSourceUtil.getConnection();
			ProductDao pd = new ProductDaoImpl(conn);
			return pd.ProductTotalCount();
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			DataSourceUtil.closeAll(conn, null, null);
		}
	}
	@Override
	public List<Category> findLevel1(Category Ct) throws Exception {
		Connection conn = DataSourceUtil.getConnection();
		try {
			ProductDao gd = new ProductDaoImpl(conn);
			return gd.findLevel1(Ct);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			DataSourceUtil.closeAll(conn, null, null);
		}
	}

	@Override
	public int del(int id,int sta,int spid) {
		Connection conn = DataSourceUtil.getConnection();
		ProductDao gd = new ProductDaoImpl(conn);
	    int de=	gd.del(id,sta,spid);
		return de;
	}

	@Override
	public List<Product> arr(int id,int spid) {
		Connection conn=DataSourceUtil.getConnection();
		ProductDao gd = new ProductDaoImpl(conn);
		List<Product> arr=gd.arr(id,spid);
		return arr;
	}

	@Override
	public int update(Product p) {
		Connection conn=DataSourceUtil.getConnection();
		ProductDao gd = new ProductDaoImpl(conn);
		int cout=gd.update(p);
		return cout;
	}
}
